package Hot100.Tree;

import java.sql.SQLOutput;
import java.util.ArrayList;
import java.util.List;

public class flatten {
    public static void main(String[] args) {
        int[] value = {1,2,5,3,4,-1,6};
        BinaryTree binaryTree = new BinaryTree();
        binaryTree.insert(value);
        new flatten().flatten(binaryTree.root);
    }
    List<Integer> list = new ArrayList<>();
    public void flatten(TreeNode root) {
        while(root != null){
            if(root.left == null){
                root = root.right;
            }
            else {
                TreeNode pre = root.left;
                while(pre.right != null){
                    pre = pre.right;
                }
                pre.right = root.right;
                root.right = root.left;
                root.left = null;
                root = root.right;
            }
        }
    }

}
